test(coverage): cover the api, the favorites view and filtered navigation #27
+430
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Solves #10. Stacked on #26, so review that one first. Only the one commit here is new.
Fills the gaps left in the suite. Nothing in here touches the network.
What was untested
api/pokemon.tshad no tests at all, which is the one module that actually calls outFavoritePokemonhad no test fileGetNextFilteredandGetPrevFilteredwere only exercised indirectly, through mocks in the list testsPokemonCardhad no test for the sprite state, so the bug where the card kept showing the previous pokemon's sprite could come back unnoticedWhat is added
api/pokemon.test.ts, five tests.fetchis stubbed, so the suite cannot reach pokeapi even by accident. Covers the url it builds, a failed response, and that an out of range id is rejected before any request goes out.FavoritePokemon.test.tsx, seven tests plus a snapshot. Props, ordering by id regardless of the order the list arrives in, that the component does not sort the caller's array in place, the selected marker, the click handler, and the empty state.PokemonCard.test.tsx, four more tests. Stepping through the four sprites, wrapping at the end, the base stat total, and a regression test for going back to the default sprite when a different pokemon is passed in.pokemonController.test.ts, five more tests for the filtered navigation. That it walks past pokemon which do not match, that it walks backwards for prev, that it stops at the ends, and that one failed fetch does not stop the walk.App.test.tsx, six tests. Loading, next and prev, prev disabled on the first pokemon, a favorite reaching local storage, a filter choice reaching session storage, and stored rules being restored on mount. This is the part that shows both storage apis in use from the user's side.Checks
vitest runtsc -beslint .prettier --checkvite buildTwo things this does not cover
Cross browser and mobile testing. The issue asks for it, but it is manual work on whatever devices we have, not something a test file can do. It needs writing up in the readme, so it belongs with #14.
An off by one in the api guard.
getPokemonByIDrejectsid < 0, but its own error message says0 < id <= 1025. So id0passes validation and goes to pokeapi, which has no pokemon 0. I left the behaviour alone rather than changing the api inside a testing PR, and the tests do not assert either way on it. Worth its own small fix.